package com.mco.socket.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author ：liao.wei
 * @date ：2023/10/7 14:43
 * @package : com.mco.socket.read
 */
public class RedisServerBIO {
	public static void main(String[] args) throws IOException {
		ServerSocket socketServer = new ServerSocket(6688);
		while (true) {
			System.out.println("模拟Redis server启动 -- 等待连接");
			Socket socket = socketServer.accept();
			System.out.println("--客户端连接成功--");
			
			InputStream inputStream = socket.getInputStream();
			int lenth = -1;
			byte[] bytes = new byte[1024];
			System.out.println("---等待读取数据---");
			while ((lenth = inputStream.read(bytes)) != -1) {
				System.out.println("---正在读取数据---");
				System.out.println("---数据内容---====>" + new String(bytes, 0, lenth));
				System.out.println();
			}
			inputStream.close();
			socket.close();
		}
	}
}
